package com.lei.sandbox;


import com.lei.sandbox.model.ExecuteCodeRequest;
import com.lei.sandbox.model.ExecuteCodeResponse;
import com.lei.sandbox.security.DenySecurityManager;
import org.springframework.stereotype.Component;

/**
 * Java原生实现沙箱（直接复用模板方法）
 */
@Component
public class JavaNativeCodeSandbox extends CodeSandboxTemplate {

    // 用于测试环境的标志
    private static final boolean IS_TEST_ENV = System.getProperty("test.env") != null;

    @Override
    public ExecuteCodeResponse executeCode(ExecuteCodeRequest executeCodeRequest) {
        // 在非测试环境中设置安全管理器以确保代码执行安全
        if (!IS_TEST_ENV) {
            System.setSecurityManager(new DenySecurityManager());
        }
        return super.executeCode(executeCodeRequest);
    }
}